<?php

namespace App\Jobs\Appraise;

use App\Service\WorkOrder\Appraise\AppraiseService;
use App\Service\WorkOrder\ProblemFeedbackService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class Appraise implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    const QUEUE_NAME = '{tiger-appraise}';

    const TYPE_APPRAISE       = 1;// 评价通知
    const TYPE_ADD_WORK_ORDER = 2;// 新增品质工单通知

    public $timeout = 1800;


    private array $data;
    private int   $type;

    /**
     * 评价通知中图片上传至飞书
     *
     * @param array $data
     * @param int $type
     */
    public function __construct(array $data, int $type = self::TYPE_APPRAISE)
    {
        $this->data = $data;//参数
        $this->type = $type;//类型
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::info("sendFSMessageJobs:", ['data' => $this->data, 'type' => $this->type]);
        switch ($this->type) {
            case self::TYPE_APPRAISE:// 评价通知
                AppraiseService::sendFSMessageJobs($this->data);
                break;
            case self::TYPE_ADD_WORK_ORDER:// 新增品质工单通知
                ProblemFeedbackService::sendFsMsg($this->data);
                break;
            default:
                Log::info('sendFSMessageJobs ErrType:', ['data' => $this->data, 'type' => $this->type]);
        }
    }
}
